
(function (a, b) {
    "use strict";
    var c = function () {
        var a = [["requestFullscreen", "exitFullscreen", "fullscreenchange", "fullscreen", "fullscreenElement"], ["webkitRequestFullScreen", "webkitCancelFullScreen", "webkitfullscreenchange", "webkitIsFullScreen", "webkitCurrentFullScreenElement"], ["mozRequestFullScreen", "mozCancelFullScreen", "mozfullscreenchange", "mozFullScreen", "mozFullScreenElement"]];
        for (var c = 0,
            d = a.length; c < d; c++) {
            var e = a[c];
            if (e[1] in b) return e
        }
    }();

    if (!c) return a.screenfull = !1;
    var d = "ALLOW_KEYBOARD_INPUT" in Element,
        e = {
            init: function () {
                return b.addEventListener(c[2],
                    function (a) {
                        e.isFullscreen = b[c[3]],
                            e.element = b[c[4]],
                            e.onchange(a)
                    }),
                    this
            },
            isFullscreen: b[c[3]],
            element: b[c[4]],
            request: function (a) {

                a = a || b.documentElement,
                    a[c[0]](d && Element.ALLOW_KEYBOARD_INPUT),
                    b.isFullscreen || a[c[0]]();
                //alert("dd");
            },
            exit: function () {
                b[c[1]]()
            },
            toggle: function (a) {
                this.isFullscreen ? this.exit() : this.request(a)
            },
            onchange: function () { }
        };
    a.screenfull = e.init()
})(window, document);
$(function () {
    var table1 = {
            zx: {
                min: 1000,
                max: 200000
            },
            h: {
                min: 200,
                max: 25000
            },
            d: {
                min: 200,
                max: 20000
            }
        },
        table2 = {
            z: 7,
            h: 3,
            x: 12,
            zd: 2,
            xd: 0
        },
        table3 = [
            ["全景", "F1", "F2", "F3", "F4", "5F", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15", "F16", "F17", "F18", "F19", "F20", "F21", "F22", "F23", "F24", "F25", "F26", "F27", "F28"],
            ["V1", "V2", "V3", "V4"]
        ];

        function fillTable1(){
            var str = "<table><tr><td>限红</td><td>庄/闲</td><td>和</td><td>对</td></tr><tr><td>最低</td><td>" + table1.zx.min + "</td><td>" + table1.h.min + "</td><td>" + table1.d.min + "</td></tr><tr><td>最高</td><td>" + table1.zx.max + "</td><td>" + table1.h.max + "</td><td>" + table1.d.max + "</td></tr></table>";
            $(".table1").html(str);
        }

        function fillTable2(){
            var str = "<table><tr><td>庄</td><td>和</td><td>闲</td><td>庄对</td><td>闲对</td></tr><tr><td>" + table2.z + "</td><td>" + table2.h + "</td><td>" + table2.x + "</td><td>" + table2.zd + "</td><td>" + table2.xd + "</td></tr></table>"
            $(".table2").html(str);
        }

        function fillTable3() {
            var str = [];
            for(var i = 0; i < table3.length; i++){
                str.push("<div class='splist'>")
                for(var j = 0; j < table3[i].length; j++){
                    str.push("<span class='spItem'>"+table3[i][j]+"</span>");
                }
                str.push("</div>");
            }
            $(".table3").html(str.join(""));
        }

        function fillTable4(){
            var str = ["<table>"];
            for(var i = 0; i < 7; i++){
                str.push("<tr>");
                for(var j =0; j<=11;j++){
                    str.push("<td></td>")
                }
                str.push("</tr>");
            }

            $(".table4").html(str.join("")+"</table>");
        }

        function fillTable5(){
            var str = ["<table>"];
            for(var i = 0; i <= 6; i++ ){
                str.push("<tr>");
                for(var j = 0; j <=39;j++){
                    str.push("<td></td>")
                }
                str.push("</tr>");
            }
            $(".table5").html(str.join("") + "</table>");
        }

        function fillTable6() {
            var str = ["<table>"];
            for (var i = 0; i <= 6; i++) {
                str.push("<tr>");
                for (var j = 0; j <= 39; j++) {
                    str.push("<td></td>")
                }
                str.push("</tr>");
            }
            
            $(".table6").html(str.join("") + "</table>");
        }
        fillTable1()
        fillTable2()
        fillTable3()
        fillTable4()
        fillTable5()
        fillTable6()

        function changeWin() {
            var w = $(window).width(),
                h = $(window).height(),mh = h-260;
                
            $(".middel").height(mh);
            $(".table3").height($(".right").height() - $(".logo").height()-$(".table1").height()-$(".table2").height()-30);
           // $(".vdioBox").height(mh-10);
        }

        changeWin();
        $(window).resize(changeWin);
    $(".qpms").click(function(e){
        eve = e || window.event;
        FullScreen();
        var l = $(this).val();
        l == "退出全屏" ? $(this).val("全屏模式") : $(this).val("退出全屏");
    });

    $(".tcxt").click(function(){
        location.href = "index.html"
    });
    function FullScreen() {
        screenfull && screenfull.toggle();
    }
    

});
    
var n1 = 0, CS_CellNum=66, g1;
var txtTie2 = null, LNR, LNC,
    c2 = 0, r2 = 0, CS_ColNum2=39, arrData2, g2;
var c3 = 0, r3 = 0, CS_ColNum3=78, arrData3, g3;
var c4 = 0, r4 = 0, CS_ColNum4=38, arrData4, g4;
var c5 = 0, r5 = 0, CS_ColNum5=38, arrData5, g5;

window.onload = function () {
    g1 = document.getElementById("g1");
    g2 = document.getElementById("g2");
    g3 = document.getElementById("g3");
    g4 = document.getElementById("g4");
    g5 = document.getElementById("g5");
    arrData2 = CreateArrData(CS_ColNum2);
    arrData3 = CreateArrData(CS_ColNum3);
    arrData4 = CreateArrData(CS_ColNum4);
    arrData5 = CreateArrData(CS_ColNum5);
}

function CreateArrData(colNum){
    var arrData = new Array(6);
    for (var i = 0; i < 6; i++) {
        arrData[i] = new Array(colNum);
        for (var j = 0; j < colNum; j++) {
            arrData[i][j] = 0;
        }
    }
    return arrData;	
}

function ClearArrData(arrData, colNum){
    for (var i = 0; i < 6; i++) {
        for (var j = 0; j < colNum; j++) {
            arrData[i][j] = 0;
        }
    }	
}

function GetNextCell(arrData, colNum, row, col, result){
    if ((arrData[row][col] > 0) ^ (result > 0)) {
    	col = 1;
	    while (arrData[0][col] != 0){
		    if (++col==colNum) return;
	    }
        row = 0;
    }
    else if (row == 5) {
        if (++col == colNum) return;
    }
    else if (arrData[row+1][col]!=0) {
        if (++col == colNum) return;
    }
    else 
        row++;
    return [row,col];
}

function DrawT1(r, b, p) {
    if (n1 >= CS_CellNum) return;
    var cx = 20 + 30 * Math.floor(n1 / 6);
    var cy = 20 + 30 * (n1 % 6);
    n1++;
    var color = "green";
    var text = "和";
    if (r > 0) {
        color = "red";
        text = "庄";
    } else if (r < 0) {
        color = "blue";
        text = "闲";
    }
    var cObj = document.createElementNS("http://www.w3.org/2000/svg", "circle");
    cObj.setAttribute("cx", cx);
    cObj.setAttribute("cy", cy);
    cObj.setAttribute("r", 14);
    cObj.setAttribute("fill", color);
    g1.appendChild(cObj);

    var tObj = document.createElementNS("http://www.w3.org/2000/svg", "text");
    tObj.setAttribute("x", cx);
    tObj.setAttribute("y", cy + 2);
    tObj.setAttribute("fill", "white");
    tObj.setAttribute("style", "font-size:20;font-weight:bold;text-anchor: middle;dominant-baseline: middle;");
    tObj.innerHTML = text;
    g1.appendChild(tObj);

    if (b) {
        cObj = document.createElementNS("http://www.w3.org/2000/svg", "circle");
        cObj.setAttribute("cx", cx - 10);
        cObj.setAttribute("cy", cy - 10);
        cObj.setAttribute("r", 4);
        cObj.setAttribute("fill", "red");
        cObj.setAttribute("stroke", "white");
        cObj.setAttribute("stroke-width", 1);
        g1.appendChild(cObj);
    }

    if (p) {
        cObj = document.createElementNS("http://www.w3.org/2000/svg", "circle");
        cObj.setAttribute("cx", cx + 10);
        cObj.setAttribute("cy", cy + 10);
        cObj.setAttribute("r", 4);
        cObj.setAttribute("fill", "blue");
        cObj.setAttribute("stroke", "white");
        cObj.setAttribute("stroke-width", 1);
        g1.appendChild(cObj);
    }
}

function DrawT2(r, b, p) {
    if (r == 0) {
        if (txtTie2 == null) {
            var cx = 352 + 14 * c2;
            var cy = 12 + 14 * r2;
            txtTie2 = document.createElementNS("http://www.w3.org/2000/svg", "text");
            txtTie2.setAttribute("x", cx);
            txtTie2.setAttribute("y", cy);
            txtTie2.setAttribute("fill", "green");
            txtTie2.setAttribute("style", "font-size:10;text-anchor: middle;dominant-baseline: middle;");
            txtTie2.innerHTML = "1";
            g2.appendChild(txtTie2);

            var lObj = document.createElementNS("http://www.w3.org/2000/svg", "line");
            lObj.setAttribute("x1", cx - 2);
            lObj.setAttribute("x2", cx + 5);
            lObj.setAttribute("y1", cy + 6);
            lObj.setAttribute("y2", cy - 1);
            lObj.setAttribute("stroke", "green");
            lObj.setAttribute("stroke-width", 0.5);
            lObj.setAttribute("shape-rendering", "crispEdges");
            g2.appendChild(lObj);
        } else {
            var _hNum = txtTie2.innerHTML;
            if (_hNum >= 9) return;
            txtTie2.innerHTML = ++_hNum;
        }
    } else {
        if (c2 > 0 || r2 > 0 || arrData2[0][0] != 0){
            txtTie2 = null;
	        var _v = GetNextCell(arrData2, CS_ColNum2, r2, c2, r)
            if (_v==undefined) return;
            r2 = _v[0];
            c2 = _v[1];
            //update the LNR,LNC for T3,T4,T5
            LNC = c2;
            if (r2==0){ //new column
                LNC--;
                for (var i=6; i > 1; i--){
                    if (arrData2[i-1][LNC]!=0) break;
                }
                LNR = i;
            }
            else
                LNR = r2;
        }
        arrData2[r2][c2] = r;
        var cx = 352 + 14 * c2;
        var cy = 12 + 14 * r2;
        var cObj = document.createElementNS("http://www.w3.org/2000/svg", "circle");
        cObj.setAttribute("cx", cx);
        cObj.setAttribute("cy", cy);
        cObj.setAttribute("r", 6);
        cObj.setAttribute("fill", "none");
        if (r > 0)
            cObj.setAttribute("stroke", "red");
        else
            cObj.setAttribute("stroke", "blue");
        g2.appendChild(cObj);

        if (b) {
            cObj = document.createElementNS("http://www.w3.org/2000/svg", "circle");
            cObj.setAttribute("cx", cx - 4);
            cObj.setAttribute("cy", cy - 4);
            cObj.setAttribute("r", 1.5);
            cObj.setAttribute("fill", "red");
            cObj.setAttribute("stroke", "white");
            cObj.setAttribute("stroke-width", 0.5);
            g2.appendChild(cObj);
        }

        if (p) {
            cObj = document.createElementNS("http://www.w3.org/2000/svg", "circle");
            cObj.setAttribute("cx", cx + 4);
            cObj.setAttribute("cy", cy + 4);
            cObj.setAttribute("r", 1.5);
            cObj.setAttribute("fill", "blue");
            cObj.setAttribute("stroke", "white");
            cObj.setAttribute("stroke-width", 0.5);
            g2.appendChild(cObj);
        }

        if (c2>1||(r2>0&&c2>0)) DrawT3();
        if (c2>2||(r2>0&&c2>1)) DrawT4();
        if (c2>3||(r2>0&&c2>2)) DrawT5();
    }
}

function GetNewColor(t) {
    var _c = LNC-t;
    var _p = 0;
    for (var i=0; i < 6; i++){
        if (arrData2[i][_c]!=0) _p++;
    }
    if ((_p==LNR)^(r2 == 0))
        return -1;
    else
        return 1;
}

function DrawT3() {
    var _clr = GetNewColor(1);
    if (c3 > 0 || r3 > 0 || arrData3[0][0] != 0){
        var _v = GetNextCell(arrData3, CS_ColNum3, r3, c3, _clr)
        if (_v==undefined) return;
        r3 = _v[0];
        c3 = _v[1];
    }
    arrData3[r3][c3] = _clr;
    var cObj = document.createElementNS("http://www.w3.org/2000/svg", "circle");
    cObj.setAttribute("cx", 348.5 + 7 * c3);
    cObj.setAttribute("cy", 104.5 + 7 * r3);
    cObj.setAttribute("r", 2.8);
    cObj.setAttribute("fill", "none");
    if (_clr>0)
        cObj.setAttribute("stroke", "red");
    else
        cObj.setAttribute("stroke", "blue");
    g3.appendChild(cObj);
}

function DrawT4() {
    var _clr = GetNewColor(2);
    if (c4 > 0 || r4 > 0 || arrData4[0][0] != 0){
        var _v = GetNextCell(arrData4, CS_ColNum4, r4, c4, _clr)
        if (_v==undefined) return;
        r4 = _v[0];
        c4 = _v[1];
    }
    arrData4[r4][c4] = _clr;
    var cObj = document.createElementNS("http://www.w3.org/2000/svg", "circle");
    cObj.setAttribute("cx", 348.5 + 7 * c4);
    cObj.setAttribute("cy", 146.5 + 7 * r4);
    cObj.setAttribute("r", 2.9);
    if (_clr>0)
        cObj.setAttribute("fill", "red");
    else
        cObj.setAttribute("fill", "blue");
    g4.appendChild(cObj);
}

function DrawT5() {
    var _clr = GetNewColor(3);
    if (c5 > 0 || r5 > 0 || arrData5[0][0] != 0){
        var _v = GetNextCell(arrData5, CS_ColNum5, r5, c5, _clr)
        if (_v==undefined) return;
        r5 = _v[0];
        c5 = _v[1];
    }
    arrData5[r5][c5] = _clr;

    var dc = 7 * c5;
    var dr = 7 * r5;
    var lObj = document.createElementNS("http://www.w3.org/2000/svg", "line");
    lObj.setAttribute("x1", 626 + dc);
    lObj.setAttribute("y1", 149 + dr);
    lObj.setAttribute("x2", 631 + dc);
    lObj.setAttribute("y2", 144 + dr);
    if (_clr>0)
        lObj.setAttribute("stroke", "red");
    else
        lObj.setAttribute("stroke", "blue");
    g5.appendChild(lObj);
}

function AddRecord(Result, BPair, PPair) {
    DrawT1(Result, BPair, PPair);
    DrawT2(Result, BPair, PPair);
}

function AddRecord2() {
    var Result = Math.floor(Math.random() * 3) - 1;
    var BPair = Math.random() > 0.495;
    var PPair = Math.random() > 0.495;
    DrawT1(Result, BPair, PPair);
    DrawT2(Result, BPair, PPair);
}

function Reset() {
    g1.innerHTML = "";
    g2.innerHTML = "";
    g3.innerHTML = "";
    g4.innerHTML = "";
    g5.innerHTML = "";
    ClearArrData(arrData2, CS_ColNum2);
    ClearArrData(arrData3, CS_ColNum3);
    ClearArrData(arrData4, CS_ColNum4);
    ClearArrData(arrData5, CS_ColNum5);
    n1 = c2 = r2 = c3 = r3 = c4 = r4 = c5 = r5 = 0;
    txtTie2 = null;
}

function Resize(width,height) {
    var mySvg=document.getElementById("tu2svg");
    mySvg.setAttribute("width", width);
    mySvg.setAttribute("height", height);
}